<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/jpg" href="/logo.jpg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Kales</title>
    <meta name="theme-color" content="#ffffff" />
    
    <!-- DNS预解析和预连接优化 -->
    <link rel="dns-prefetch" href="https://fonts.googleapis.com">
    <link rel="dns-prefetch" href="https://fonts.gstatic.com">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    
    <!-- 关键资源预加载 -->
    <link rel="modulepreload" href="/src/main.tsx">
    <link rel="modulepreload" href="/src/app.tsx">
    <link rel="modulepreload" href="/src/pages/home/index.tsx">
    
    <!-- 优化字体加载策略 - 使用font-display: swap避免FOIT -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&family=Noto+Sans:wght@300;400;500;600;700&family=Noto+Sans+JP:wght@300;400;500;600;700&display=swap" rel="stylesheet" media="print" onload="this.media='all'">
    <noscript><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&family=Noto+Sans:wght@300;400;500;600;700&family=Noto+Sans+JP:wght@300;400;500;600;700&display=swap" rel="stylesheet"></noscript>
    
    <!-- 内联关键CSS - 防止字体闪烁 -->
    <style>
      /* 系统字体回退 */
      body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
      }
      
      /* 首屏加载动画 */
      #root {
        min-height: 100vh;
      }
      
      /* 预加载动画 */
      .loading-skeleton {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: loading 1.5s infinite;
      }
      
      @keyframes loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
      }
    </style>
    <script>
      // 防止暗黑/白昼切换时的白屏闪烁：在 React 渲染前设置初始 data-theme 与 class
      (function() {
        // 在最早阶段设置语言相关属性，避免首屏字体闪烁
        try {
          var allowed = ['en','es','fr','ja','ru'];
          var savedLocale = localStorage.getItem('app_locale');
          var navLang = ((navigator.language || navigator.userLanguage || 'ja').slice(0,2));
          var locale = allowed.indexOf(savedLocale) >= 0 ? savedLocale : (allowed.indexOf(navLang) >= 0 ? navLang : 'ja');
          document.documentElement.setAttribute('data-locale', locale);
          document.documentElement.setAttribute('lang', locale);
        } catch (e) {}
        try {
          var stored = localStorage.getItem('kale-dark-mode');
          if (stored === '1') {
            document.documentElement.classList.add('dark');
            document.documentElement.setAttribute('data-theme', 'dark');
            var m = document.querySelector('meta[name="theme-color"]');
            if (m) m.setAttribute('content', '#000000');
            return;
          }
          if (stored === '0') {
            document.documentElement.classList.remove('dark');
            document.documentElement.setAttribute('data-theme', 'light');
            var m2 = document.querySelector('meta[name="theme-color"]');
            if (m2) m2.setAttribute('content', '#ffffff');
            return;
          }
          // fallback to system preference
          if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
            document.documentElement.classList.add('dark');
            document.documentElement.setAttribute('data-theme', 'dark');
            var m3 = document.querySelector('meta[name="theme-color"]');
            if (m3) m3.setAttribute('content', '#000000');
          } else {
            document.documentElement.classList.remove('dark');
            document.documentElement.setAttribute('data-theme', 'light');
          }
        } catch (e) {}
      })();
    </script>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>
